home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / Inside Mac Movie Toolbox Code / mtb8.c < prev    next >
Encoding:
Text File  |  1992-10-22  |  2.2 KB  |  81 lines  |  [TEXT/KAHL]

  1. //    Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  2.  
  3. #include "mtb.h"
  4.  
  5. void AddVideoSamplesToMedia (Media theMedia, 
  6.                                         const Rect *trackFrame)
  7. {
  8.     long                                 maxCompressedSize;
  9.     GWorldPtr                                 theGWorld = nil;
  10.     long                                 curSample;
  11.     Handle                                 compressedData = nil;
  12.     Ptr                                compressedDataPtr;
  13.     ImageDescriptionHandle                                 imageDesc = nil;
  14.     CGrafPtr                                 oldPort;
  15.     GDHandle                                 oldGDeviceH;
  16.     OSErr                                 err = noErr;
  17.  
  18.     err = NewGWorld (    &theGWorld, 
  19.                         16,        // pixel depth             
  20.                         trackFrame, 
  21.                         nil, 
  22.                         nil, 
  23.                         (GWorldFlags) 0 );
  24.     CheckError (err, "\pNewGWorld");
  25.     
  26.     LockPixels (theGWorld->portPixMap);
  27.  
  28.     err = GetMaxCompressionSize (theGWorld->portPixMap,
  29.                                     trackFrame, 
  30.                                     0, // let ICM choose depth
  31.                                     codecNormalQuality, 
  32.                                     'rle ', 
  33.                                     (CompressorComponent) anyCodec,
  34.                                     &maxCompressedSize    );
  35.     CheckError (err, "\pGetMaxCompressionSize" );
  36.  
  37.     compressedData = NewHandle(maxCompressedSize);
  38.     CheckError( MemError(), "\pNewHandle" );
  39.     
  40.     MoveHHi( compressedData );
  41.     HLock( compressedData );
  42.     compressedDataPtr = StripAddress( *compressedData );
  43.  
  44.     imageDesc = (ImageDescriptionHandle)NewHandle(4);
  45.     CheckError( MemError(), "\pNewHandle" );
  46.         
  47.     GetGWorld (&oldPort, &oldGDeviceH);
  48.     SetGWorld (theGWorld, nil);
  49.     
  50. //••••••• changed to <= 30
  51.     for (curSample = 1; curSample <= 30; curSample++) {
  52.         EraseRect (trackFrame);
  53.         DrawFrame(trackFrame, curSample);
  54.  
  55.         err = CompressImage (    theGWorld->portPixMap, 
  56.                                     trackFrame, 
  57.                                     codecNormalQuality,
  58.                                     'rle ',
  59.                                     imageDesc, 
  60.                                     compressedDataPtr );
  61.         CheckError( err, "\pCompressImage" );
  62.         
  63.         err = AddMediaSample(theMedia,             
  64.                                     compressedData,
  65.                                     0,            // no offset in data
  66.                                     (**imageDesc).dataSize,  
  67.                                     60,            // frame duration = 1/10 sec
  68.                                     (SampleDescriptionHandle)imageDesc, 
  69.                                     1,            // one sample
  70.                                     0,            // self-contained samples
  71.                                     nil);
  72.         CheckError( err, "\pAddMediaSample" );
  73.     }
  74.     
  75.     SetGWorld (oldPort, oldGDeviceH);
  76.     
  77.     if (imageDesc) DisposeHandle ((Handle)imageDesc);
  78.     if (compressedData) DisposeHandle (compressedData);
  79.     if (theGWorld) DisposeGWorld (theGWorld);
  80. }
  81.